//
//  AministrationAddressVC.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/11.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//
/**
数据的来源是哪里 底层向上层一层一层传递的吗？
 
 编辑功能
 删除功能
 */

#import "AministrationAddressVC.h"
#import "CommonMacro.h"
#import "AddNewAddressVC.h"
#import "ChoseDefaultAddressView.h"

@interface AministrationAddressVC ()
@property (nonatomic,strong) UIButton *editButton;
@property (nonatomic,strong) UIButton *deleteButton;
//@property (nonatomic,strong) AddNewAddressVC *addNewAddress;
@end

@implementation AministrationAddressVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"选择默认收货地址";
    self.view.backgroundColor = [UIColor whiteColor];
    
    //右侧按钮
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"新增" style:UIBarButtonItemStylePlain target:self action:@selector(addNewAddress)];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    
//     self.addNewAddress = [[AddNewAddressVC alloc] init];
    [self createSubViews];
}

#pragma mark 管理地址
- (void)addNewAddress
{
    AddNewAddressVC *addNewAddress = [[AddNewAddressVC alloc] init];
    UINavigationController *addNewNav = [[UINavigationController alloc]initWithRootViewController:addNewAddress];
    [self presentViewController:addNewNav animated:YES completion:nil];
    
}

#pragma mark 创建tableView
- (void)createSubViews
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

#pragma mark 数据源
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"Cell";
    ChoseDefaultAddressView *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell = [[ChoseDefaultAddressView alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
      //编辑按钮
    self.editButton = [[UIButton alloc] initWithFrame:CGRectMake(cell.bounds.size.width*0.65, 10, cell.bounds.size.width*0.13, cell.bounds.size.height*0.5)];
    [cell addSubview:self.editButton];
    self.editButton.tag = 1000;
    [self.editButton setTitle:@"编辑" forState:UIControlStateNormal];
    [self.editButton setTitleColor:UIColorWithRGBA(198, 190, 176, 1) forState:UIControlStateNormal];
    [self.editButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    self.editButton.layer.borderColor = UIColorWithRGBA(211, 201, 174, 1).CGColor;
    self.editButton.layer.borderWidth = 1;
    self.editButton.layer.cornerRadius = 3;
    self.editButton.clipsToBounds = YES;
    [self.editButton addTarget:self action:@selector(editDeleteButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //删除按钮
    self.deleteButton = [[UIButton alloc] initWithFrame:CGRectMake(self.editButton.frame.size.width+self.editButton.frame.origin.x+5, 10, cell.bounds.size.width*0.13, cell.bounds.size.height*0.5)];
    [cell addSubview:self.deleteButton];
    self.deleteButton.tag = 1001;
    [self.deleteButton setTitle:@"删除" forState:UIControlStateNormal];
    [self.deleteButton setTitleColor:UIColorWithRGBA(198, 190, 176, 1) forState:UIControlStateNormal];
    [self.deleteButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    self.deleteButton.layer.borderColor = UIColorWithRGBA(211, 201, 174, 1).CGColor;
    self.deleteButton.layer.borderWidth = 1;
    self.deleteButton.layer.cornerRadius = 3;
    self.deleteButton.clipsToBounds = YES;
    [self.deleteButton addTarget:self action:@selector(editDeleteButton:) forControlEvents:UIControlEventTouchUpInside];


    cell.accessoryType = UITableViewCellAccessoryNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 160;
}


#pragma mark 编辑 删除
- (void)editDeleteButton:(UIButton *)button
{
    NSLog(@"dianjidianjidianji");
    if (button.tag==1000) {
       
        AddNewAddressVC *addNewAddress = [[AddNewAddressVC alloc] init];
        UINavigationController *addNewNav = [[UINavigationController alloc]initWithRootViewController:addNewAddress];
        [self presentViewController:addNewNav animated:YES completion:nil];

    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}



@end
